package com.huluobo.a2302mdmdemo.videos

import com.huluobo.a2302mdmdemo.videos.entity.CommentEntity
import com.huluobo.lib_base.entity.VideoEntity
import com.huluobo.lib_base.BaseRepo
import com.huluobo.lib_base.Res
import com.huluobo.lib_base.entity.VideoEntityItem
import com.huluobo.lib_base.room.VideoDao
import com.huluobo.lib_http.HttpType
import com.huluobo.lib_http.NetworkFactory
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

/**
 *  Created by LC on 2025/8/4.
 */
class VideoRepo @Inject constructor(private val videoDao: VideoDao) : BaseRepo() {
    private val apiService by lazy { NetworkFactory.factory(HttpType.VIDEO).create(ApiService::class.java) }

    fun getVideos(currentPage: Int, pageSize: Int): Flow<Res<VideoEntity>> {
        return apiService.getVideos(currentPage, pageSize)
    }

    fun likeVideo(videoId: Int): Flow<Res<Any>> {
        return apiService.likeVideo(videoId)
    }

    fun noLikeVideo(videoId: Int): Flow<Res<Any>> {
        return apiService.noLikeVideo(videoId)
    }

    fun getComments(videoId: Int): Flow<Res<CommentEntity>> {
        return apiService.getComments(videoId = videoId)
    }

    fun collectVideo(videoEntityItem: VideoEntityItem): Flow<Long> {
        return flow { emit(videoDao.insertVideoInfo(videoEntityItem)) }
    }

    fun getCollectVideos(): Flow<List<VideoEntityItem>> {
        return flow { emit(videoDao.queryAllVideoInfo()) }
    }
}